/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.mvc.views.singleviews
{
	import com.puny.utils.ColorGenerator;
	import com.puny.utils.Random;
	
	import flash.display.Shape;
	
	/**
	 * ShapeParticleView: It has a number of particle. 
	 * @author Mitsuru
	 * @example
	 * <listing>
	 * // 100 red particles will be created.
	 * // Each particle has 10 pixel radius.
	 * new ShapeParticleView(0xFF0000,10,100); 
	 * 
	 * // 100 gray particles will be created.
	 * // Each particle has 10 pixel radius.
	 * // RGB values are same.
	 * new ShapeParticleView([0x22,0xAA],10,100);
	 *  
	 * // 100 cyan particles will be created.
	 * // Each particle has 10 pixel radius.
	 * // Red value is between 0xAA and 0xCC.
	 * // Green value is 0.
	 * // Blue value is 0xBB.
	 * new ShapeParticleView(new ColorGenerator([0xAA,0xCC],0,0xBB),10,100);
	 * 
	 * </listing>
	 * @see com.puny.utils.ColorGenerator
	 */
	public class ShapeParticleView extends ParticleView
	{
		private var _color:*;
		protected var _radius:Number;

		/**
		 * Constructor
		 * @param color ColorGenerator instance, Array instance, or uint value.
		 * @param radius radius of particle
		 * @param total total number of particle that this view will have
		 * 
		 */
		public function ShapeParticleView(color:*, radius:Number, total:int)
		{
			_radius = radius;
			_color = color;
			super(null, null, total);
		}
		
		protected function getColor():uint {
			if (_color is ColorGenerator) {
				return _color.getColor();
			} else if(_color is Array) {
				var c:uint = uint(Random.between(_color[0],_color[1]));
				return c * 0x10000 + c * 0x100 + c;
			}
			return _color;			
		}
		
		override protected function setup():void {
			var shape:Shape
			for(var i:int = 0;i < _total;i++) {
				shape = new Shape();
				shape.graphics.beginFill(getColor(),1);
				shape.graphics.drawCircle(0,0,_radius);
				shape.graphics.endFill();
				shape.cacheAsBitmap = true;
				_mcs.push(shape);
			}
		}
	}
}